package edu.ccut.saturn.workflow.query;

import java.util.List;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;

public class ValidateLoginDeptidsAndFinishDeptIds extends DefaultComponent {

	@SuppressWarnings("unchecked")
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		List<String> loginDeptIds = (List<String>) parameterContext
				.getParameterValue(0);
		List<String> finishDeptIds = (List<String>) parameterContext
				.getParameterValue(1);
		boolean flag = validateDeptidsAndDeptIds(loginDeptIds, finishDeptIds);
		parameterContext.setParameter(2, flag);
	}

	/**
	 * 判断登陆部门集合和前几步活动完成者部门集合是否同一部门
	 * 
	 * @param loginDeptIds
	 * @param finishDeptIds
	 * @return
	 */
	private boolean validateDeptidsAndDeptIds(List<String> loginDeptIds,
			List<String> finishDeptIds) {
		boolean flag = false;
		for (int i = 0; i < loginDeptIds.size(); i++) {
			String id = loginDeptIds.get(i);
			for (int j = 0; j < finishDeptIds.size(); j++) {
				String targId = finishDeptIds.get(j);
				if(id.indexOf(targId)>-1||targId.indexOf(id)>-1){
					flag = true;
					break;
				}
			}
		}
		return flag;
	}

}
